package com.hrm;

import java.util.Date;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hrm.dao.GroupsMapper;
import com.hrm.dao.PeopleMapper;
import com.hrm.dao.PeopleNetsMapper;
import com.hrm.entity.Groups;
import com.hrm.entity.People;
import com.hrm.entity.PeopleNets;
import com.hrm.util.Config;


public class InitData {
	static SqlSession session=null;
	static{
		 //读取spring配置文件
        BeanFactory beanFactory = new ClassPathXmlApplicationContext(
                "spring.xml");
        //通过spring配置文件生成的beanFactory获得SqlSessionFactory
        SqlSessionFactory factory = (SqlSessionFactory) beanFactory
                .getBean("sqlSessionFactory");
        //获得SqlSession
        session = factory.openSession();
	}
	public static void main(String[] args) {
		PeopleMapper peopleMapper =session.getMapper(PeopleMapper.class);
		GroupsMapper groupsMapper =session.getMapper(GroupsMapper.class);
		PeopleNetsMapper pNetsMapper = session.getMapper(PeopleNetsMapper.class);
//		People people = new People();
//		people.setPid(10000);
//		people.setPname("紫");
//		people.setUid(-1);
//		people.setUname("朱朝强");
//		people.setPstate(Config.STATE_OFFLINE);
//		people.setPheader("Alienware07.png");
//		people.setPsay("昨晚梦见带小梁和小孙回老家玩了。");
//		peopleMapper.insertPeople(people);
		People people1 = new People();
		people1.setPid(10001);
		people1.setPname("别说爱我$$");
		people1.setUid(-1);
		people1.setUname("范冬冬");
		people1.setPstate(Config.STATE_OFFLINE);
		people1.setPheader("Alienware06.png");
		people1.setPsay("想念那一季的海风");
		//peopleMapper.insertPeople(people1);
		People people2 = new People();
		people2.setPid(10002);
		people2.setPname("王妃");
		people2.setUid(-1);
		people2.setUname("王妃");
		people2.setPstate(Config.STATE_OFFLINE);
		people2.setPheader("Alienware05.png");
		people2.setPsay("公主长大了就会变成王妃，但愿所有成为王妃的公主依然很快乐");
		//peopleMapper.insertPeople(people2);
		People people3 = new People();
		people3.setPid(10003);
		people3.setPname("品味舍得");
		people3.setUid(-1);
		people3.setUname("刘安民");
		people3.setPstate(Config.STATE_OFFLINE);
		people3.setPheader("Alienware04.png");
		people3.setPsay("我最好的朋友生了个女儿，最先想到的是...");
		//peopleMapper.insertPeople(people3);
		People people4 = new People();
		people4.setPid(10004);
		people4.setPname("瞳");
		people4.setUid(-1);
		people4.setUname("朱朝勇");
		people4.setPstate(Config.STATE_OFFLINE);
		people4.setPheader("Alienware08.png");
		people4.setPsay("人生三大遗憾：不会选择，不坚持选择，不断选择。");
		//peopleMapper.insertPeople(people4);
		People people5 = new People();
		people5.setPid(10005);
		people5.setPname("瞳宝宝");
		people5.setUid(-1);
		people5.setUname("杜欣桐");
		people5.setPstate(Config.STATE_OFFLINE);
		people5.setPheader("Alienware09.png");
		people5.setPsay("早睡早起！");
		//peopleMapper.insertPeople(people5);
		
		Groups groups = new Groups();
		groups.setGid(1);
		groups.setGname("我爱的人");
//		groupsMapper.insertGroups(groups);
		Groups groups1 = new Groups();
		groups1.setGid(2);
		groups1.setGname("高中好友");
//		groupsMapper.insertGroups(groups1);
		Groups groups2 = new Groups();
		groups2.setGid(3);
		groups2.setGname("兄弟姐妹");
//		groupsMapper.insertGroups(groups2);
		
		People people =peopleMapper.selectPeopleById(1);
		PeopleNets peopleNets=new PeopleNets();
		peopleNets.setFrompid(people.getPid());
		peopleNets.setGid(groups.getGid());
		peopleNets.setTopid(people1.getPid());
		peopleNets.setCreatetime(new Date());
		pNetsMapper.insertPeopleNets(peopleNets);
		peopleNets.setId(0);
		peopleNets.setTopid(people2.getPid());
		peopleNets.setCreatetime(new Date());
		pNetsMapper.insertPeopleNets(peopleNets);
		peopleNets.setId(0);
		peopleNets.setGid(groups1.getGid());
		peopleNets.setTopid(people3.getPid());
		peopleNets.setCreatetime(new Date());
		pNetsMapper.insertPeopleNets(peopleNets);
		peopleNets.setId(0);
		peopleNets.setGid(groups2.getGid());
		peopleNets.setTopid(people4.getPid());
		peopleNets.setCreatetime(new Date());
		pNetsMapper.insertPeopleNets(peopleNets);
		peopleNets.setId(0);
		peopleNets.setGid(groups2.getGid());
		peopleNets.setTopid(people5.getPid());
		peopleNets.setCreatetime(new Date());
		pNetsMapper.insertPeopleNets(peopleNets);
		
		
	}

}